<template>
	<view>
		<!-- <button @click="upgrade">upgrade</button> -->
		<view class="download">
			<uni-popup ref="popup_upgrade" type="center">
				<view class="upgrade">
					<view class="logo">
						<!-- <image src="../static/upgrade.png" mode="widthFix" /> -->
					</view>
					<view class="content">
						<view class="title">
							<text>{{"新功能提示"}}</text>
						</view>
						<view class="container">
							<view class="descriptions">
								<text>{{"本次版本更新内容:"}}</text>
							</view>
							<view class="details">
								<view class="item" v-for="(item,updateIndex) in updateList" :key="updateIndex">
									<text>{{item.tips_name}}</text>
									<text @tap="clickSure(item)" class="experience">立即体验</text>
								</view>
							</view>
						</view>
						<view class="btn-group">
							<view class="cancel" @click="hiddenUppop">
								<text>取消</text>
							</view>
							<view class="confirm" @click="hiddenUppop">
								<text>确定</text>
							</view>
						</view>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	export default { 
		props : {
			
		},
		data: () => ({
			// 版本代码
			versionCode: 28,
			// 版本字符串
			versionStr: "1.0.0530",
			// 是否更新
			upgrading: false,
			// 下载时间
			downloadTime: 0,
			// 定时器
			timer: null,
			// 是否强制更新
			isForceUpgrade: false,
			// 下载任务
			downloadTask: null,
			// 下载地址
			downloadUrl: "",
			updateList : [],
			
			
		}),
		// 使用的组件
		components: {
			uniPopup,
		},
		mounted() {
			// this.upgrade()
		},
		methods: {
			clickSure(item){
				this.$refs.popup_upgrade.close();
				if(item.tips_link){
					uni.navigateTo({
						url:item.tips_link
					})
				}
			},
			// 取消更新
			hiddenUppop() {
				this.$refs.popup_upgrade.close();
			},
			// 检测更新
			upgrade() {
				let hasNewVersion = false;
				var clent=uni.getSystemInfoSync().platform  
				let param = {
					platform:clent,
					app_id:this.config.APP_ID,
					build_version:this.config.build_version,
				}
				this.common.http.request('/api/v1/feature/tips','GET', param,res => {
					if(res.data.code == 0 && res.data.data) {
						let show_tips = uni.getStorageSync('show_tips');
						if(show_tips == this.config.build_version){
							hasNewVersion = false;
							return;
						}
						this.updateList = res.data.data;
						hasNewVersion = true
						if (hasNewVersion) {
							// console.log(111)
							uni.setStorageSync('show_tips',this.config.build_version);
							this.$refs.popup_upgrade.open();
						}
					}
				})
			},
		},
	};
</script>

<style>
	.download .logo {
		width: 208rpx;
	}
	.item{
		margin-top: 20rpx;
	}
	.experience{
		margin-left: 20rpx;
		text-decoration: underline;
		color: #0d386e;
	}
	.download .upgrade {
		position: relative;
		background: #fff;
		width: 468rpx;
		min-height: 238rpx;
		border-radius: 20rpx;
	}

	.download .logo image {
		width: 208rpx;
		position: absolute;
		top: -80rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
	}

	.download .content {
		padding-top: 80rpx;
	}

	.download .content .title {
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
	}

	.download .content .container {
		color: #666;
	}

	.download .content .container .descriptions {
		padding: 0rpx 30rpx;
		text-align: center;
		font-size: 28rpx;
	}

	.download .content .container .details,
	.download .content .prpgroess {
		padding: 16rpx 46rpx;
		box-sizing: border-box;
		font-size: 24rpx;
	}

	.download .content .prpgroess {
		padding: 16rpx 22rpx;
		margin: 20rpx 0;
	}

	.download .content .btn-group {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.download .content .btn-group view {
		width: 200rpx;
		height: 68rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 14rpx;
		font-size: 24rpx;
		border-radius: 16rpx;
		line-height: 1.5;
	}

	.download .content .btn-group view:last-child {
		background: #ef5656;
		color: #fff;
	}
</style>
